﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using DAL;

namespace BLL
{
    public class AcademyService
    {
        AcademyDAL academyDAL = new AcademyDAL();

        public void CreateAcademy(BoAcademy academy)
        {
            academy.ACA_ID = System.Guid.NewGuid().ToString();
            academyDAL.Insert(academy);
        }

        public void UpdateAcademy(BoAcademy academy)
        {
            academyDAL.Update(academy);
        }
       /* public void DeleteAcademy(string aca_ID)
        {
            if (new DbCommon.DbHelper().GetCount("Major", "MAJ_ACADEMY='" + aca_ID + "'and MAJ_IsShow='true'") > 0)
            {
                System.Windows.Forms.MessageBox.Show("该学院下还有专业，请先删除专业，再删除学院!");
            }
            else
            {
                academyDAL.Delete(aca_ID);
            }
        }*/
        public void DeleteAcademy(BoAcademy academy)
        {
            if (new DbCommon.DbHelper().GetCount("Major", "MAJ_ACADEMY='" + academy.ACA_ID + "'and MAJ_IsShow='true'") > 0)
            {
                System.Windows.Forms.MessageBox.Show("该学院下还有专业，请先删除专业，再删除学院!");
            }
            else
            {
                academyDAL.Delete(academy.ACA_ID);
            }
            if (new DbCommon.DbHelper().GetCount("Teachers", "TEA_ACADEMY='" + academy.ACA_ID + "'and TEA_IsShow='true'") > 0)
            {
                System.Windows.Forms.MessageBox.Show("该学院下还有教师，请先删除教师，再删除学院!");
            }
            else
            {
                academyDAL.Delete(academy.ACA_ID);
            }
            if (new DbCommon.DbHelper().GetCount("Competitions", "COM_ACADEMY='" + academy.ACA_ID + "'and COM_IsShow='true'") > 0)
            {
                System.Windows.Forms.MessageBox.Show("该学院下还有竞赛，请先删除竞赛，再删除学院!");
            }
            else
            {
                academyDAL.Delete(academy.ACA_ID);
            }

            
            //new BLL.ClassService().DeleteClassesByMajorId(major.MAJ_ID);

        }

        //public void DeleteAcademy(BoAcademy academy)
        //{
        //    academyDAL.Delete(academy.ACA_ID);
        //    new BLL.ClassService().DeleteClassesByAcademyId(academy.ACA_ID);
        //    new BLL.MajorService().DeleteMajorByAcademyId(academy.ACA_ID);
        //    new BLL.CompetitionService().DeleteCompetitionsByAcademyId(academy.ACA_ID);
        //    new BLL.TeacherService().DeleteTeacherByAcademyId(academy.ACA_ID);
        //}
        public void DeleteAcademyByLocalId(string localId)
        {
            BLL.MajorService majorservice = new MajorService();
            academyDAL.DeleteAcademyByLocalId(localId);
            IList<BoAcademy> academylist = getAcademyByLocal(localId);
            foreach (BoAcademy model in academylist)
            {
                majorservice.DeleteMajorByAcademyId(model.ACA_ID);
            }
        }
   

        public BoAcademy getAcademy(string id)
        {
            return academyDAL.GetModel(id);
        }
        public IList<BoAcademy> getAcademyByLocal(string localId)
        {
            return academyDAL.GetAcademyByLocal(localId);
        }

        public List<BoAcademy> getAllAcademies()
        {
            return academyDAL.GetAcademies();
        }

        /// <summary>
        /// 得到分页的数据列表
        /// </summary>
        /// <param name="orderCon">排序条件</param>
        /// <param name="sqlCon">查询条件</param>
        /// <param name="pagesize">每页显示大小</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="records">返回查询到的记录</param>
        /// <returns>返回对象列表</returns>
        public IList<BoAcademy> getPageCompetitions(string sqlCon, string orderCon, int pagesize, int pageIndex, out int records)
        {
            return academyDAL.getPageCompetitions(sqlCon, orderCon, pagesize, pageIndex, out records);
        }
        public IList<BoAcademy> getAcademiesByLocal(string id)
        {
            return academyDAL.GetAcademyByLocal(id);
        }
        /// <summary>
        /// 通过学院的名字来获取学院对象
        /// </summary>
        /// <param name="AcademyName">学院的名字</param>
        /// <returns>返回学院的对象</returns>
        public List<BoAcademy> getAcademyByName(string AcademyName)
        {
            return academyDAL.getAcademyByName(AcademyName.Trim());
        }

        /// <summary>
        /// 通过学院的院系号来获取学院对象
        /// </summary>
        /// <param name="AcademyCode">学院号</param>
        /// <returns>返回对象</returns>
        public BoAcademy getAcademyByCode(string AcademyCode)
        {
            return academyDAL.getAcademyByCode(AcademyCode);
        }
    }
}
